package com.mdd.admin.controller.competition;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ICompetitionRuleService;
import com.mdd.admin.validate.competition.CompetitionRuleCreateValidate;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.entity.competition.CompetitionRule;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/adminapi/competition/rule")
@Api(tags = "赛事规则管理")
public class CompetitionRuleController {

    @Autowired
    private ICompetitionRuleService competitionRuleService;


    @GetMapping("/detail")
    @ApiOperation(value="赛事列详情")
    public AjaxResult<CompetitionRule> detail(@RequestParam(value = "id",required = false) Integer id,
                                              @RequestParam("competitionId") Integer competitionId,
                                              @RequestParam("schedule") Integer schedule
    ) {
        CompetitionRule detail = competitionRuleService.detail(id,competitionId,schedule);
        return AjaxResult.success(detail);
    }

    @Log(title = "赛事列新增")
    @PostMapping("/add")
    @ApiOperation(value="赛事列新增")
    public AjaxResult<Object> add(@Validated @RequestBody CompetitionRuleCreateValidate createValidate) {
        competitionRuleService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "赛事列编辑")
    @PostMapping("/edit")
    @ApiOperation(value="赛事列编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody CompetitionRuleCreateValidate updateValidate) {
        competitionRuleService.edit(updateValidate);
        return AjaxResult.success();
    }

}
